<?php

use app\models\AsrAudioClassify;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

$this->title = '';
$lc_id = 0;
$parent_id = 0;
if (!empty($lc)){
    //业务流程的id
    $audio_id= $_GET['id'];
    //业务流程的id
    $lc_id= !empty($lc->id)?$lc->id:0;
    //业务流程的父节点的id
    $parent_id=  !empty($lc->parent_id)?$lc->parent_id:0;
    //文件的id串
    $file_id= !empty($lc->file_id)?$lc->file_id:"";
}
?>

<link href="../assets/public/css/asr-audio/asr-audio.min.css" rel="stylesheet">

<link href="../assets/public/css/asr-audio/main.css" rel="stylesheet">

<script src="../assets/public/js/angular.js/1.7.2/angular.min.js"></script>

<script src="../assets/public/js/pekeUpload.min.js"></script>

<div ng-app="myApp" name="myApp">
<!--    <div ng-include="'../tpl/header.html'"></div>-->
    <!--    话术流程导航   -->
    <header class="main-header" style="z-index:1; margin: -30px -15px;">
        <!--    话术流程导航   -->
        <nav class="navbar navbar-default " style="margin-left: 0px;background-color: #0071a6">
            <div class="collapse navbar-collapse pull-left" id="navbar-collapse">
                <ul class="nav nav-pills nav-justified">
                    <a style="color:white; margin: 15px;" id="back" class="pull-left"
                       href="index?page=<?php echo isset($_GET['page']) ? $_GET['page'] : 0; ?>&per-page=<?php echo isset($_GET['per-page']) ? $_GET['per-page'] : 0; ?>"><i
                                class="fa fa-backward"></i> 返回</a>
                    <li class="dropdown" id="main-system"><a
                                href="update?id=<?php echo $id ?>&page=<?php echo isset($_GET['page']) ? $_GET['page'] : 0; ?>&per-page=<?php echo isset($_GET['per-page']) ? $_GET['per-page'] : 0; ?>"
                                class="dropdown-toggle" data-toggle="dropdown">主流程</a>
                    </li>
                    <li class="dropdown" id="profession">
                        <a href="profession?id=<?php echo $id ?>&page=<?php echo isset($_GET['page']) ? $_GET['page'] : 0; ?>&per-page=<?php echo isset($_GET['per-page']) ? $_GET['per-page'] : 0; ?>"
                           class="dropdown-toggle" data-toggle="dropdown" id="profession">业务流程</a>
                    </li>
                    <li class="dropdown active" id="system-flow">
                        <a href="system?id=<?php echo $id ?>&page=<?php echo isset($_GET['page']) ? $_GET['page'] : 0; ?>&per-page=<?php echo isset($_GET['per-page']) ? $_GET['per-page'] : 0; ?>"
                           class="dropdown-toggle" data-toggle="dropdown" id="system">系统流程
                        </a>
                    </li>
                    <li class="dropdown" id="stop">
                        <a href="end?id=<?php echo $id ?>&page=<?php echo isset($_GET['page']) ? $_GET['page'] : 0; ?>&per-page=<?php echo isset($_GET['per-page']) ? $_GET['per-page'] : 0; ?>"
                           class="dropdown-toggle" data-toggle="dropdown">结束</a>
                    </li>
                </ul>
            </div>
        </nav>

    </header>

    <!--內容-->
    <div class="frame-body-box"  ng-controller="commonCtrl">

        <div class="frame-right-box">

            <div id="answerDetail" class="" style="display: block;margin-top: 45px">

                <div class="answerContent">

                    <!--內容內的頭-->
                    <div class="title">
                        <h4>话术设置</h4>
                    </div>

                    <!--导航栏下面的所有的数据-->
                    <div class="answerMain">
                        <!--左边的显示节点列表数据-->
                        <div class="ansLeft">
                            <div class="sonNav">
                                <div class="sonList">
                                    <ul class="son2 scene0 open" ng-click="toggleNodeList()" ng-class="{'open':toggleNodeListShow,'':!toggleNodeListShow}">
                                        <li class="businessTit"><p>系统流程<em class="triangle"></em></p></li>
                                        <li ng-repeat="item in nodeList" parent_id="{{item.parent_id}}" id="{{item.id}}" style="{{item.id==lcid?'color:#77b5fd':''}}">
                                            <div class="sTit" ng-click="changeItemColor($event)">
                                                <p class="">{{item.name}}</p>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>

                        <!--右边的显示数据-->
                        <div class="ansRight">
                            <div class="flowMain flow">

                                <!--话术节点名称,命中该标签客户意向分,所属语境,该节点当前是属于哪个语境-->
                                <div class="mBox hiddenToVisible">

                                    <div class="fmBox">
                                        <div class="main-title">
                                            <span class="title-left">话术节点名称：</span>
                                            <div class="el-input">
                                                <input id="name" type="text" autocomplete="off" maxlength="6" class="el-input__inner" ng-model="name">
                                            </div>
                                        </div>
                                        <div class="flowScore">
                                        <span class="title-left">命中该标签客户意向分
                                            <div class="el-input">
                                                <input id="intent_score" type="text" autocomplete="off" maxlength="3" class="el-input__inner" ng-model="intent_score">
                                            </div>分
                                        </span>
                                        </div>
                                    </div>
                                    <img src="../assets/public/img/asr-audio/reflect1.png" class="reflect">
                                </div>

                                <!--关键词内容,关键词有效范围-->
                                <div class="mBox hiddenToVisible">
                                    <div class="line"></div>
                                    <div class="idenKeyWords">
                                        <span class="title-left">关键词内容：</span>
                                        <div class="el-textarea">
                                        <textarea  id="keywords"  maxlength="1000" placeholder="多个关键词用英文的“;”分割,例如：你是;你是谁" class="el-textarea__inner" style="min-height: 31px;" ng-model="keywords"></textarea>
                                        </div>
                                    </div>
                                    <img src="../assets/public/img/asr-audio/reflect2.png" class="reflect">
                                </div>


                                <!--设置语音内容,添加语音内容 文件上传-->
                                <div class="mBox">
                                    <div class="line">
                                    </div>
                                    <div class="flowText">
                                        <div id="files_content" class="flowContents" style="scroll-x:hidden" >
                                            <div class="flowContents" ng-repeat="item in filelist" >
                                                <div class="flowContent" id="files_content">
                                                    <span class="title-left">设置语音内容：<br>
                                                        （第{{$index+1}}条）
                                                    </span>
                                                    <div class="el-textarea">
                                                        <textarea maxlength="1000" rows="5" class="el-textarea__inner" style="min-height: 31px;" ng-model="item.content"></textarea>
                                                    </div>
                                                    <div class="audios">
                                                        <div class="audio">
                                                            <audio controls="controls" class="voice" src="..{{item.filepath}}"></audio>
                                                        </div>
                                                        <button type="button" class="el-button btnLeft el-button--primary">
                                                            <span><img src="../assets/public/img/asr-audio/turnText.png"></span>
                                                        </button>
                                                        <div class="btnRight">
                                                            <button type="button" ng-click="deleteFile($event)" index="{{$index}}"  class="el-button r_btn el-button--primary delete_sound delete_file">
                                                                <span index="{{$index}}">删除语音</span>
                                                            </button>
                                                            <div class="upload-demo">
                                                                <div tabindex="0" class="el-upload el-upload--text">
                                                                    <form method="post" enctype="multipart/form-data" index="{{$index}}">
                                                                        <button type="button" ng-click="uploadFile($event)" class="el-button el-button--primary el-button--small">
                                                                            <span><img src="../assets/public/img/asr-audio/shangc.png">上传语音</span>
                                                                        </button>
                                                                        <input type="file" name="file" accept=".wav,.mp3" id="upload_file_{{$index}}" value="" class="el-upload__input">
                                                                    </form>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <i></i>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="addAudio">
                                            <span class="title-left">添加语音内容：</span>
                                            <div class="addAudioBtn" id="addFile" ng-click="addFile()">
                                                +
                                            </div>
                                        </div>
                                    </div>
                                    <img src="../assets/public/img/asr-audio/reflect3.png" class="reflect">
                                </div>

                                <!--设置识别意向,添加识别意向-->
                                <div class="mBox" id="intents_step" style="display: none" >
                                    <div class="line"></div>
                                    <div class="discern"  >
                                        <span class="title-left" style="float: left;height: 100px;display:inline;">
                                            <div style="height: 50px;line-height:50px;vertical-align: middle;">识别意向词语  :</div>
                                            <div style="height: 50px;line-height:50px;vertical-align: middle;">识别意向词语  :</div>
                                        </span>
                                        <div style="float: left;overflow-x: auto;width: 600px;height: 110px;padding:0px 8px " >
                                            <div style="float: left;height: 100px;width:{{intentList.length*150}}px;" id="intents_content">
                                                <div style="width: 150px;padding:0px;margin: 0px;float: left;overflow:hidden;position:relative" ng-repeat="item in intentList">
                                                    <deleteintenthover-directive></deleteintenthover-directive>
                                                    <div index="{{$index+1}}"></div>
                                                    <div style="height:50px;line-height:50px;vertical-align: middle;">
                                                        <button type="button" class="el-button letterBtn affrim el-button--primary" ng-click="showNextKeywordIntent($event)" index="{{$index+1}}"><span index="{{$index+1}}">{{item.intent_name}}</span></button>
                                                    </div>
                                                    <div style="height:50px;line-height:50px;vertical-align: middle;">
                                                        <button type="button" class="el-button letterBtn nextStep el-button--primary" index="{{$index+1}}" ng-click="showNextIntent($event)" ><span>下一步</span></button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--设置语音内容,添加语音内容 文件上传-->
                                    <div class="flowText">
                                        <div class="addAudio">
                                            <span class="title-left">添加识别意向：</span>
                                            <div class="addAudioBtn" id="addIntent" ng-click="showIntent()">
                                                +
                                            </div>
                                        </div>
                                    </div>
                                    <img src="../assets/public/img/asr-audio/reflect4.png" class="reflect">
                                </div>


                                <!--reflect-->
                                <div class="mBox"> <img src="../assets/public/img/asr-audio/reflect5.png" class="reflect"></div>

                                <!--reflect-->
                                <div class="mBox"> <img src="../assets/public/img/asr-audio/reflect6.png" class="reflect"></div>

                                <!--保存与删除节点的按钮-->
                                <div class="flowBtns">
                                    <button type="button" id="save_lc" ng-click="save_lc()" class="el-button flowBtnSure el-button--primary"><span>保存</span></button>
<!--                                    <button type="button" id="delete_lc" ng-click="delete_lc()" class="el-button flowBtnCancel el-button--primary"><span>删除节点</span></button>-->
                                </div>

                            </div>
                        </div>

                        <!--掩盖层-->
                        <div class="el-loading-mask" style="display: none;">
                            <div class="el-loading-spinner">
                                <svg viewBox="25 25 50 50" class="circular">
                                    <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                </svg>
                            </div>
                        </div>
                    </div>


                    <!--隐藏的窗口弹出窗1-->
                    <div class="windowPop ployKeywords" id="next_keyword_intent" ng-model="next_keyword_intent_id">
                        <div class="increased-form">
                            <div class="increased-title">
                                <span>{{next_keyword_intent_name}}</span>
                                <i></i>
                            </div>
                            <div class="increased-body">
                                <div class="PopBox1">
                                    <div class="el-textarea">
                                    <textarea rows="2" id="keyword_intent_content" placeholder="请输入内容" maxlength="1000" class="el-textarea__inner" style="min-height: 31px;" ng-model="next_keyword_intent_content"></textarea>
                                    </div>
                                    <div class="flowBtns">
                                        <button type="button" id="save_next_keyword_intent" ng-click="saveNextKeywordIntent()" class="el-button el-button--primary"><span>保存并退出</span></button>
                                        <button type="button" id="cancel_next_keyword_intent" ng-click="cancelNextKeywordIntent()" class="el-button el-button--default"><span>取消</span></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>


                    <!--隐藏的窗口弹出窗2 请选择跳转话术节点-->
                    <div class="windowPop continue" id="next_intent">
                        <div class="increased-form">
                            <div class="increased-title">
                                <span>请选择跳转话术节点</span><i></i>
                            </div>
                            <div id="next_intent">
                                <div class="increased-body">
                                    <div class="continueTitle">
                                        <ul class="hiddenToVisible">
                                            <li class="hiddenToVisible">
                                        <span class="title-left" style="height: 40px;line-height:40px;vertical-align: middle;">
                                            话术类型：
                                        </span>
                                                <div class="el-select" style="height: 40px;line-height:40px;vertical-align: middle;">
                                                    <select id="asrkeyword-keyword_id" name="AsrKeyword[keyword_id]" value="0" class="form-control">
                                                        <option value="0" selected="selected">主流程</option>
                                                        <option value="1">业务流程</option>
                                                        <option value="2">系统流程</option>
                                                        <option value="3">结束流程</option>
                                                    </select>
                                                </div>
                                            </li>
                                            <li class="hiddenToVisible">
                                        <span class="title-left" style="height: 40px;line-height:40px;vertical-align: middle;">
                                            话术节点：
                                        </span>
                                                <div class="el-select" style="height: 40px;line-height:40px;vertical-align: middle;">
                                                    <select id="asrkeywordclassify-id" name="AsrKeyword[keyword_id]" value="0" class="form-control">
                                                    </select>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                    <div class="flowContentBox flowBox" id="fileContents">
                                        <div class="flowContent">
                                            <span class="title-left">语音内容：</span>
                                            <div class="el-textarea is-disabled">
                                                <textarea disabled="disabled" rows="5" class="el-textarea__inner" style="min-height: 31px;"></textarea>
                                            </div>
                                            <div class="audios">
                                                <div class="audio">
                                                    <audio controls="controls" src="" class="voice"></audio>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="flowBtns">
                                        <button type="button" id="save_next_intent" ng-click="save_next_intent($event)"  class="el-button el-button--primary"><span>保存</span>
                                        </button>
                                        <button type="button" id="flush_next_intent" ng-click="flush_next_intent($event)"  class="el-button el-button--warning"><span>清空</span>
                                        </button>
                                        <button type="button" id="cancel_next_intent" ng-click="cancel_next_intent($event)"  class="el-button nextCancel el-button--primary">
                                            <span>取消</span>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!--隐藏的窗口弹出窗4 新增intent-->
                    <div class="windowPop SceneSet" id="add_intent">
                        <div class="increased-form">
                            <div class="increased-title">
                                <span>新增意向</span>
                                <i></i>
                            </div>
                            <div class="increased-body">
                                <div class="PopBox1">
                                    <div class="el-textarea">
                                    <textarea rows="1" name="intent_name" placeholder="请输入意向名称" maxlength="8" class="el-textarea__inner" style="min-height: 11px;"></textarea>
                                    </div>
                                </div>
                                <br>
                                <div class="el-textarea">
                                <textarea rows="2"  name="intent_content"  placeholder="请输入意向关键字，用;隔开" maxlength="10000" class="el-textarea__inner" style="min-height: 31px;"></textarea>
                                </div>
                                <div class="flowBtns">
                                    <button type="button" id="save_intent" ng-click="saveIntent()" class="el-button el-button--primary"><span>保存并退出</span></button>
                                    <button type="button" id="cancel_intent" ng-click="cancelIntent()" class="el-button el-button--default"><span>取消</span></button>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>

</div>
<!--<script src="../assets/public/js/asr-audio/system-controller.js"></script>-->
<!--自己寫的js m 代表模型 v 代表视图 c 代表控制器-->
<script>
    //切换导航
    $('#navbar-collapse ul li').unbind('click').click(function () {
        $('#navbar-collapse ul li').removeClass('active');
        $(this).addClass('active');
        var href = $(this).children()[0].href
        console.log($(this).children()[0].href);
        location.href = href;
    });
    //导航栏的鼠标经过事件
    $(".main-header li").hover(function () {//导航栏的鼠标经过事件
        $(this).addClass("open");
    },function () {
        $(this).removeClass("open");
    });
</script>
<script>
    //注册angular.js
    var app = angular.module('myApp', []);
    window.temp_jQyery = $;
    app.controller('commonCtrl', function($scope,$http,MyService) {
        $  = window.temp_jQyery;
        //文件的id
        $scope.audio_id = <?= $audio_id ?>;
        //流程id
        $scope.lcid = <?= $lc_id ?>;
        //定义双向绑定的数据 名称
        $scope.name = "";
        //定义双向绑定的数据 分数
        $scope.intent_score = "";
        //定义双向绑定的数据 关键词内容
        $scope.keywords = "";
        //文件的id串
        $scope.file_id = "";
        //定义双向绑定的数据 文件列表
        $scope.filelist = "";
        $scope.options = {//文件上传的配置
            allowedExtensions: "wav",
            invalidExtError: "无效的文件类型",
            maxSize: 0,
            sizeError: "文件太大",
            showPreview: true,
            showFilename: true,
            showPercent: true,
            showErrorAlerts: true,
            errorOnResponse: "上传文件出错",
            onSubmit: false,
            url: "uploadfile",
            data: null,
            limit: 1,
            limitError: "上传文件出错",
            delfiletext: "移除",
            onFileError: function(file, error) {//文件上传失败后
                if (error){
                    layer.msg('上传文件失败！');
                }
            },
            onFileSuccess: function(file, data) {//文件上传成功后
                MyService.getFileList();
                layer.msg('上传文件成功！');
            }
        };
        //定义双向绑定的数据 意图列表
        $scope.intentList = "";
        $scope.nodeList = <?= json_encode($nodeList) ?>;
        $scope.save_lc = function () {
                var name = $("#name").val();
                var intent_score = $("#intent_score").val();
                var keywords = $("#keywords").val();
                var data = {name:name,intent_score:intent_score,keywords:keywords};
                MyService.save_lc($scope.lcid,data).then(function () {
                    MyService.getNodeList($scope.audio_id).then(
                        function successCallback(response) {
                            $scope.nodeList = response.data.Data;
                        }
                    );
                    layer.msg("修改成功！");
                },function () {
                    layer.msg("修改失败！");
                });
        }
        $scope.delete_lc = function () {
            layer.confirm('确定删除该条记录？', {
                btn: ['确定', '取消'] //可以无限个按钮
            },function () {
                MyService.delete_lc($scope.lcid);
            },function () {
            });
        }
        //进入就加载流程数据
        MyService.getLc($scope.lcid).then(
            function successCallback(response) {
                $scope.name = response.data.Data.name;
                $scope.intent_score = response.data.Data.intent_score;
                $scope.keywords = response.data.Data.keywords;
                $scope.file_id = response.data.Data.file_id;
            }
        );
        //加载文件数据
        MyService.getFileList($scope.lcid).then(
            function successCallback(response) {
                $scope.filelist = response.data.Data;
                setTimeout(() => {
                        $('.flowContents').scrollTop(1000000);
                        $('.flowContents .el-textarea__inner').eq($scope.filelist.length-1).select();
                    },
                    100);
        });
        //加载意图列表
        MyService.getIntentList($scope.lcid).then(
            function successCallback(response) {
                $scope.intentList = response.data.Data;
                if ($scope.intentList<1){
                    $("#intents_step .discern").css("display","none");
                }else{
                    $("#intents_step .discern").css("display","block");
                }
                setTimeout(() => {
                        $('.flowContents').scrollLeft(1000000);
                        $('.flowContents .el-textarea__inner').eq($scope.intentList.length-1).select();
                    },
                    100);
            }
        );
        //展开
        $scope.toggleNodeListShow = true;
        $scope.toggleNodeList = function(){
            $scope.toggleNodeListShow  = ! $scope.toggleNodeListShow;
        };
        //改变本身的item的颜色,然后获取数据，
        $scope.changeItemColor = function(event){
            var that = $(event.target);
            //让每一个其他的li变色为黑色
            that.parents("ul").children("li").not(".businessTit").each(function () {
                $(this).removeAttr("style");
            });
            //让每一个其他的li变色为蓝色
            that.parents("li").css("color","#4fa2fe");
            //不要展开压缩
            $scope.toggleNodeListShow = false;
            //获取数据
            $scope.lcid = that.parents("li").attr("id");
            MyService.getLc($scope.lcid).then(
                function successCallback(response) {
                    $scope.name = response.data.Data.name;
                    $scope.intent_score = response.data.Data.intent_score;
                    $scope.keywords = response.data.Data.keywords;
                    $scope.file_id = response.data.Data.file_id;
                    MyService.getIntentList($scope.lcid).then(
                        function successCallback(response) {
                            $scope.intentList = response.data.Data;
                            if ($scope.intentList<1){
                                $("#intents_step .discern").css("display","none");
                            }else{
                                $("#intents_step .discern").css("display","block");
                            }
                            setTimeout(() => {
                                    $('.flowContents').scrollLeft(1000000);
                                    $('.flowContents .el-textarea__inner').eq($scope.intentList.length-1).select();
                                },
                                100);
                        }
                    );
                }, function errorCallback(response) {
                });
            MyService.getFileList($scope.lcid).then(
                function successCallback(response) {
                    $scope.filelist = response.data.Data;
                    setTimeout(() => {
                            $('.flowContents').scrollTop(1000000);
                            $('.flowContents .el-textarea__inner').eq($scope.filelist.length-1).select();
                        },
                        100);
                }, function errorCallback(response) {
                });
        };
        //改变本身的item的颜色,然后获取数据，
        $scope.changeOverColor = function(event){
            var that = $(event.target);
            that.css("color","#4fa2fe");
        };
        //改变本身的item的颜色,然后获取数据，
        $scope.changeLeaveColor = function(event){
            var that = $(event.target);
            that.css("color","#000000");
        };
        //点击新增文件列表里面一个文件，
        $scope.addFile = function(){
            //新增文件
            $scope.filelist.push({content: '', filepath: "",files_id: '', });
            setTimeout(() => {
                    $('.flowContents').scrollTop(1000000);
                    $('.flowContents .el-textarea__inner').eq($scope.filelist.length-1).select();
                },
                100);
        };
        //点击上传文件列表里面一个文件，
        $scope.uploadFile = function(event){
            var that = $(event.target);
            var obj = that.parents("form");
            var index = parseInt(obj.attr("index"));
            var button = obj.find("button");
            var input = obj.find("input");
            input.remove();
            button.after('<input type="file" id="upload_file_'+index+'" name="file" accept=".wav,.mp3" value="大大" class="el-upload__input">');
            //当input里面的内容改变时触发
            $('#upload_file_'+index).bind("change",function () {
                $scope.options.url = "uploadfile?files_id="+$scope.filelist[index].files_id+"&content="+$scope.filelist[index].content+"&audio_id="+$scope.audio_id+"&lc_id="+$scope.lcid+"&classify=app\\models\\AsrKeywordXtlcClassify";
                $('#upload_file_'+index).pekeUpload($scope.options);
                $('#upload_file_'+index).unbind("change");
            });
            obj.find("input").click();
        };
        //点击删除文件列表里面一个文件，
        $scope.deleteFile = function(event){
            var that = $(event.target);
            var index = parseInt($that.attr("index"));
            layer.confirm('确定删除该条记录？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(btnIndex){
                MyService.deleteFile(that,index,$scope.filelist[index]).then(
                    function successCallback(response) {
                        $scope.filelist.splice(index,1);
                        layer.msg('删除成功！');
                    }, function errorCallback(response) {
                        res = false;
                        layer.msg('删除失败！');
                    });
            }, function(btnIndex){
                layer.msg('已取消！');
            });
        };
        //点击新增意图列表里面一个意图，
        $scope.showIntent = function(){
            $("#add_intent").css('display', 'block');
        };
        $scope.cancelIntent = function(){
            $("#add_intent").css('display', 'none');
        };
        $scope.saveIntent = function(){
            var data =
            {
                keyword_id: 0,
                intent_name: $("#add_intent [name='intent_name']").val(),
                content: $("#add_intent [name='intent_content']").val(),
                classify_id: $scope.lcid,
                classify_type: 2
            };
            MyService.addIntent(data).then(
                function successCallback(response) {
                    $("#add_intent").css("display", "none");
                    MyService.getIntentList($scope.lcid).then(
                        function successCallback(response) {
                            $scope.intentList = response.data.Data;
                            layer.msg('添加成功！');
                            setTimeout(() => {
                                    $('.flowContents').scrollLeft(1000000);
                                    $('.flowContents .el-textarea__inner').eq($scope.intentList.length-1).select();
                                },
                                100);
                        }
                    );;
                }, function errorCallback(response) {
                    layer.msg('添加失败！');
            });
        };
        //下一个关键词显示
        $scope.showNextKeywordIntent = function(event) {
            var that = $(event.target);
            var index = parseInt(that.attr("index"));
            var keyword_id = $scope.intentList[index - 1].keyword_id;
            $("#next_keyword_intent").css('display', 'block');
            MyService.findNextKeywordIntent(keyword_id).then(
                function successCallback(response) {
                    $scope.next_keyword_intent_name = response.data.Data.next_intent.intent_name;
                    $scope.next_keyword_intent_content = response.data.Data.next_intent.content;
                }, function errorCallback(response) {
                    layer.msg('查询失败！');
                });
        }
        $scope.saveNextKeywordIntent = function(){
            $("#next_keyword_intent").css('display', 'block');
        };
        $scope.cancelNextKeywordIntent = function(){
            $("#next_keyword_intent").css('display', 'none');
        };
        // $scope.showNextIntent = function (event) {
        //     var that = $(event.target);
        //     var index = that.attr("index");
        //     intent = $scope.intentList[index];
        //     $("#next_intent").css('display','block');
        //     this.next_intent_id = id;
        //     findNextIntent1();
        //     $("#continue .increased-title span").html("请选择检测到“"+$(this).attr("myname")+"”后跳转到的话术节点");
        //     $("#continue").attr("my-id",id);
        // }
    });

    // 指令的编写
    app.directive('deleteintenthoverDirective', function(MyService){
        return {
            restrict : "AEMC",
            template : '<image src="../assets/public/img/delete.png" title="删除该条记录" style="z-index=9999;cursor:pointer;width: 15px;display:none;height:15px;margin-left:130px;position:absolute;"/>',
            scope:true,
            replace: true,
            link: function (scope,elements,attrs) {
                elements.parent().hover(function () {
                    var index = parseInt(elements.next().attr("index"));
                    $(this).children("img").css("display","block");
                    $(this).children("img").bind('click',function () {
                        layer.confirm('确定删除该条记录？', {
                            btn: ['确定', '取消'] //可以无限个按钮
                        }, function(btnIndex){
                            var id = scope.intentList[index-1].keyword_id;
                            MyService.deleteIntent(id).then(
                                function successCallback(response) {
                                    scope.intentList.splice(index-1,1);
                                    layer.msg('删除成功！');
                                }, function errorCallback(response) {
                                    layer.msg('删除失败！');
                                });
                        }, function(btnIndex){
                            layer.msg('已取消！');
                        });
                    });
                    $(this).children("img").hover(function () {
                        $(this).css("height",18);
                        $(this).css("width",18);
                    },function () {
                        $(this).css("height",15);
                        $(this).css("width",15);
                    })
                },function () {
                    elements.css("display","none");
                });
            },
        };
    });
    app.directive('changeItemColor',function (MyService) {
        return {
            restrict : "AE",
            template : '',
            scope:{},
            replace: false,
            link: function (scope,element,attrs) {
                element.bind("click", function () {

                });
            },
        };
    });

    // 在 MyService 中注入 factory "MyService"
    app.service('MyService', function(MyFactory){

        this.getLc = function(lcid) {return MyFactory.getLc(lcid);}
        this.getFileList = function(lcid) {return MyFactory.getFileList(lcid);}
        this.getNodeList = function(audio_id) {return MyFactory.getNodeList(audio_id);}
        this.getIntentList = function(lcid) {return MyFactory.getIntentList(lcid);}
        this.upload = function(that) {return MyFactory.upload(that);}
        this.deleteFile = function(file) {return MyFactory.deleteFile(file);}
        this.deleteIntent = function(id) {return MyFactory.deleteIntent(id);}
        this.addIntent = function(data) {return MyFactory.addIntent(data);}
        this.findNextKeywordIntent = function(keyword_id) {return MyFactory.findNextKeywordIntent(keyword_id);}
        this.delete_lc = function(lcid) {return MyFactory.delete_lc(lcid);}
        this.save_lc = function(lcid,data) {return MyFactory.save_lc(lcid,data);}

    });

    //注册factory，这里定义所有的共用函数
    app.factory('MyFactory', function($http) {
        var factory = {};

        //拿到流程
        factory.getLc = function(lcid) {
            return $http({
                method: 'POST',
                url: 'find-lc?classify=app\\models\\AsrKeywordXtlcClassify&id='+lcid
            });
        };

        //拿到文件列表
        factory.getFileList = function (lcid) {
            return $http({
                method: 'POST',
                url: 'find-file-list?classify=app\\models\\AsrKeywordXtlcClassify&id='+lcid
            });
        }

        //拿到节点列表
        factory.getNodeList = function (audio_id) {
            return $http({
                method: 'POST',
                url: 'find-node-list?classify=app\\models\\AsrKeywordXtlcClassify&id='
            });
        }

        //拿到意图列表
        factory.getIntentList = function (lcid) {
            return $http({
                method: 'POST',
                url: 'find-intent-list?classify=app\\models\\AsrKeywordXtlcClassify&id='+lcid,
                async:false,
            });
        }

        //删除文件
        factory.deleteFile = function (file) {
            return $http({
                method: 'POST',
                url: "delete-files?files_id=" + file.files_id+"&audio_id="+ file.audio_id+"&lc_id="+ file.lcid
            });
        }

        //删除文件
        factory.deleteIntent = function (id) {
            return $http({
                method: 'POST',
                url: "delete-intent?id=" + id,
            });
        }

        //新增文件
        factory.addIntent = function (data) {
            //添加意向
            return $.ajax({
                url: 'add-intent',
                method: 'POST',
                dataType:'json',
                data: {data:JSON.stringify(data)},
            });
        }

        //新增文件
        factory.findNextKeywordIntent = function (keyword_id) {
            //添加意向
            return $http({
                method: 'POST',
                url: 'find-next-intent?id='+keyword_id,
                dataType:'json',
            });
        }
        //删除整个流程
        factory.delete_lc = function (lcid) {
            //添加意向
            return $http({
                method: 'POST',
                url: 'delete-lc?id='+lcid,
                dataType:'json',
            });
        }

        //保存整个流程
        factory.save_lc = function (lcid,data) {
            //添加意向
            return $.ajax({
                url: "save-lc?id="+lcid+"&classify=app\\models\\AsrKeywordXtlcClassify",
                method: 'POST',
                dataType:'json',
                data: {data:JSON.stringify(data)},
            });
        }

        return factory;
    });
</script>